package cn.cvs.service.impl;

import cn.cvs.dao.RentMapper;
import cn.cvs.entity.Rent;
import cn.cvs.service.RentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class RentServiceImpl implements RentService {
    @Autowired
    private RentMapper mapper;
    @Override
    public List<Rent> list(int pageIndex,int pageSize) {
        int startIndex = (pageIndex - 1) * pageSize;
        List<Rent> list = null;
        list = mapper.list(startIndex,pageSize);
        return list;
    }

    @Override
    public int pageCount(int pageSize) {
        int pageCount = 0;
        int count = mapper.count();
        pageCount = count % pageSize == 0 ?(count / pageSize) : (count / pageSize) + 1;
        return pageCount;
    }

    @Override
    public int update(int id,int status) {
        return mapper.update(id,status);
    }

    @Override
    public int delete(int id) {
        return mapper.delete(id);
    }

    @Override
    public int add(Rent rent) {
        return mapper.add(rent);
    }

    @Override
    public List<Rent> listByUserName(int pageIndex, int pageSize, String userName) {
        int startIndex = (pageIndex - 1) * pageSize;
        return mapper.listByUserName(startIndex,pageSize,userName);
    }


}
